#!/usr/bin/env python
#  -*- coding: utf-8 -*-
__author__ = 'chengzhi'

from tqsdk import TqApi, TqAuth
import datetime
# import csv
# import pandas as pd
api = TqApi(auth=TqAuth("houzx910", "houzx289310"))
# 获得 c2311 tick序列的引用
ticks = api.get_tick_serial("DCE.c2311")

klines11 = api.get_kline_serial("DCE.c2311", 30)

print("ticks", ticks)
print("klines11", klines11)
# api.close()
# ticks2 = api.get_tick_serial("DCE.c2311")
# print("ticks2", ticks2)
# api.close()
# while True:
#     api.wait_update()
#     if api.is_changing(klines11.iloc[-1], "datetime"):
#         print("11新K线", datetime.datetime.fromtimestamp(klines11.iloc[-1]["datetime"] / 1e9))
#     if api.is_changing(klines11.iloc[-1], "close"):
#         print("11K线变化", datetime.datetime.fromtimestamp(klines11.iloc[-1]["datetime"] / 1e9), klines11.close.iloc[-1])